package slim3.demo.controller.tpe;


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;



public class ExtractCitiesNamesTools {
	
		
	public static void main(String[] argv) throws Exception{
	    
	    //get all
//	    ExtractCitiesNamesTools test = new ExtractCitiesNamesTools();
//        test.getNames();
        
//	    String temp = "東根市 (日本):山形機場";	    
//	    String country, airport, city;
//	    
//        airport = temp.substring(temp.indexOf(':')+1);
//        System.out.println(airport);
//        
//        city = temp.substring(0, temp.indexOf('(')-1);
//        System.out.println(city);
//        
//        country = temp.substring(temp.indexOf('(')+1, temp.indexOf(')'));
//        System.out.println(country);
	    
	    String temp = "東根市 日本 山形機場";       
        String country, airport, city;
        String temp3[] = null;
        
        temp3 = temp.split(" ");
        
        airport = temp3[2];
        System.out.println(airport);
        
        city = temp3[0];
        System.out.println(city);
        
        country = temp3[1];
        System.out.println(country);
        
	    
        
	}
	
	
	
	
	public void getNames() throws Exception{

	    
		try {

		  
			/**
			 * read from URL
			 */
//			URL tsa = new URL("http://www.tsa.gov.tw/CustomerSet/tsa/tp_FlightSchedule/RSS_news.asp?id={FE8E2C05-9D2C-482F-9919-4A3A3387E71A}&dfc=1");
//						
//			URLConnection urlc = tsa.openConnection();
//			urlc.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
//			urlc.setDoOutput(true);
//			urlc.setDoInput(true);
//			
////			BufferedReader in = new BufferedReader(
////	            new InputStreamReader(tsa.openStream()));
//			BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
//
////	        String inputLine;
////	        while ((inputLine = in.readLine()) != null)
////	            System.out.println(inputLine);
////	        in.close();
  
    
			/**
			 * read from file
			 */
			BufferedReader in = new BufferedReader(new FileReader("1.txt"));
  
  
			/**
			 * process code below
			 */
			String str;

				while ( (str = in.readLine()) != null) {
				    
						
					 if (str.contains("} else if")) {
					     System.out.println(str.trim());
					 } else {
//					     System.out.println("    " + str.trim());
//					     String a;
					     String[] b;
					     str = str.substring(str.indexOf(" \"")+2, str.indexOf("\";"));
//                         System.out.println(str);
                         b = str.split("-");
//                         System.out.println(b.length);
//                         System.out.println(b[0]);
//                         System.out.println(b[1]);
                         System.out.println("    temp = \"" + b[1] + " (" + b[0] + ")\";");
					 }
						 
				}
					 
			
			in.close();
		    
		    
			} catch (IOException e) {
			    e.getStackTrace();
			}
			
	}
	  
	  
	  

}
